package com.example.myweb.Service.Auth.Impl;

import com.example.myweb.Dto.FeedItemDTO;
import com.example.myweb.Repository.JpaRepository.FeedRepository;
import com.example.myweb.Service.Auth.FeedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FeedServiceImpl implements FeedService {

    @Autowired
    private FeedRepository feedRepository;

    @Override
    @Transactional(readOnly = true)
    public Page<FeedItemDTO> getUserFeed(Long authorId, Pageable pageable) {
        // 让 getUserFeed 也调用新的 findFeed 方法
        return feedRepository.findFeed(List.of(authorId), pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<FeedItemDTO> getPublicFeed(Pageable pageable) {
        return feedRepository.findFeed(null, pageable);
    }

    // --- 实现新方法 ---
    @Override
    @Transactional(readOnly = true)
    public Page<FeedItemDTO> getFollowingFeed(List<Long> authorIds, Pageable pageable) {
        return feedRepository.findFeed(authorIds, pageable);
    }
}